package com.itqf.controller;

import com.github.pagehelper.PageInfo;
import com.itqf.entity.DingDan;
import com.itqf.entity.Product;
import com.itqf.service.DingDanService;
import com.itqf.vo.TableVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author: Panjianwei
 * @date: 2019/12/18 21:58
 * 代码是一门艺术，需要我们细细用心品味！
 */
@Controller
@ResponseBody
public class DingDanController {
    @Autowired
    private DingDanService dingDanService;
    @RequestMapping("/dingdan/findall")
    public TableVo<DingDan> findall(String dUsername , String proName, @RequestParam(defaultValue ="-1") int Status , @RequestParam(defaultValue = "1") int pageindex,@RequestParam(defaultValue = "1")int pagesize)
    {
        PageInfo<DingDan> pageInfo = dingDanService.findall(pageindex,pagesize, dUsername, proName, Status);
        for (DingDan dingDan : pageInfo.getList()) {
            String dUsername1 = dingDan.getDUsername();
            System.out.println(dUsername1);
        }
//        layui需要总条数 和数据集合
        TableVo<DingDan> dingDanTableVo = new TableVo<>();

        dingDanTableVo.setData(pageInfo.getList());
        dingDanTableVo.setCount((int)pageInfo.getTotal());
        return dingDanTableVo;
    }
    @RequestMapping("/dingdan/insert")
    public int insert(DingDan dingDan)
    {
        int insert = dingDanService.insert(dingDan);
        return insert;
    }
//    查询所有商品
    @RequestMapping("/dingdan/findallproduct")
    public List<Product> findallProduct()
    {
        List<Product> products = dingDanService.findallProduct();
        return products;
    }
//    修改
//    (1)主键查询
    @RequestMapping("/dingdan/findbyGid")
    public DingDan findbyGid(int dId)
    {
        DingDan dingDan = dingDanService.findbyGid(dId);
        return dingDan;
    }
//    (2)修改
    @RequestMapping("/dingdan/update")
    public int update(DingDan dingDan)
    {
        int update = dingDanService.update(dingDan);
        return update;
    }
//    刪除
@RequestMapping("/dingdan/delete")
public int delete(int dId){
        int delete = dingDanService.delete(dId);
        return delete;
    }
}
